package thread;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolDemo {
    public static int count = 0;
    public static int count2 = 1;
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(2);
        for (int i = 0;i<5;i++){
            Runnable r = new Runnable() {

                public void run() {
                    count++;
                    Thread r = Thread.currentThread();
                    System.out.println(r +"" +count + "正在运行...");
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                    }
                    synchronized ("") {
                        System.out.println(r + "" + count2 + "执行完毕");
                        count2++;
                    }
                }
            };
            threadPool.execute(r);
            System.out.println("任务已分配");
        }
        threadPool.shutdown();
    }
}
